package com.cskaoyan.gateway.controller.user;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.user.IVerifyService;
import com.mall.user.annotation.Anoymous;
import com.mall.user.dto.UserVerifyRequest;
import com.mall.user.dto.UserVerifyResponse;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * VerifyController
 * created by feng on 7/21/21
 */
@RestController
@RequestMapping("/user")
public class VerifyController {

    @Reference(timeout = 30000, check = false, retries = 0)
    IVerifyService iVerifyService;

    /**
     * 激活服务
     */
    @Anoymous
    @GetMapping("/verify")
    public ResponseData verifyEmail(@RequestParam String uid, @RequestParam String username) {
        // 1. 判断uid中的username与发过来的username是否相同
        UserVerifyRequest userVerifyRequest = new UserVerifyRequest();
        userVerifyRequest.setUserName(username);
        userVerifyRequest.setUuid(uid);

        // 2. 判断是否抛出异常
        UserVerifyResponse response = iVerifyService.verify(userVerifyRequest);

        if (!"000000".equals(response.getCode())) {
            return new ResponseUtil<>().setErrorMsg(Integer.parseInt(response.getCode()), response.getMsg());
        }
        return new ResponseUtil<>().setData(response);
    }
}